<?php
/**
 * 新闻动态
 * Created by PhpStorm.
 * User: xsh
 * Date: 2018/4/12  10:06
 */
namespace app\pc\controller;
use think\Controller;

class Dynamic extends Base
{
    /*
    *	构造函数
    */
    function __construct(){
        parent::__construct();
    }

    //首页
    public function index(){
        $dynamic = db('dynamic');

        $dynamic_category_result = db('dynamic_category')->where(array('category_name'=>'高企专栏'))->field('id')->select();
        
        $dynamic_category_result = array_column($dynamic_category_result, 'id');
        $where['category'] = array('in', $dynamic_category_result);
        $where['is_display'] = 1;

        $data = $dynamic->field('id,title,content,picture,create_time')->where($where)->order('order_by','desc')->paginate(5);

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('data', $data);
        return $this->fetch('Dynamic/index');
    }

    //详情
    public function detail(){
        $id = input('id');
        $data = db('dynamic')
            ->where('id',$id)
            ->find();
        $this->assign('data', $data);
        return $this->fetch('dynamic_detail');
    }
}